package com.pc_project.controller;


import com.pc_project.domain.User;
import com.pc_project.domain.VO.JsonVO;
import com.pc_project.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/user")
@Api(tags = "用户分组")
public class UserController {
    @Autowired
    UserService userService;

    @ApiOperation("登录接口")
    @PostMapping("login")
    public JsonVO login (@RequestBody User user) {
        return userService.login(user.getUsername(), user.getPassword());
    }

    @PreAuthorize("hasAnyAuthority('user','replyuser')")
    @ApiOperation("登出接口")
    @PostMapping("logout")
    public JsonVO logout() {
        return userService.logout();
    }

    @ApiOperation("注册接口")
    @PostMapping("reg")
    public JsonVO reg(User user) {

        return userService.reg(user);
    }


    @ApiOperation("更改密码")
    @PostMapping("/updatePwd")
    public JsonVO<String> updatePwd(@RequestBody Map<String,String> map){
        return userService.updatePwd(map.get("oldPwd"), map.get("newPwd"));
    }




}
